<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of confmat</title>
  <meta name="keywords" content="confmat">
  <meta name="description" content="CONFMAT Compute a confusion matrix.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../menu.html">Home</a> &gt;  <a href="#">ReBEL-0.2.7</a> &gt; <a href="#">netlab</a> &gt; confmat.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../menu.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="menu.html">Index for .\ReBEL-0.2.7\netlab&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>confmat
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>CONFMAT Compute a confusion matrix.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [C,rate]=confmat(Y,T) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">CONFMAT Compute a confusion matrix.

    Description
    [C, RATE] = CONFMAT(Y, T) computes the confusion matrix C and
    classification performance RATE for the predictions mat{y} compared
    with the targets T.  The data is assumed to be in a 1-of-N encoding,
    unless there is just one column, when it is assumed to be a 2 class
    problem with a 0-1 encoding.  Each row of Y and T corresponds to a
    single example.

    In the confusion matrix, the rows represent the true classes and the
    columns the predicted classes.  The vector RATE has two entries: the
    percentage of correct classifications and the total number of correct
    classifications.

    See also
    <a href="conffig.html" class="code" title="function fh=conffig(y, t)">CONFFIG</a>, <a href="demtrain.html" class="code" title="function demtrain(action);">DEMTRAIN</a></pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="conffig.html" class="code" title="function fh=conffig(y, t)">conffig</a>	CONFFIG Display a confusion matrix.</li><li><a href="demmlp2.html" class="code" title="">demmlp2</a>	DEMMLP2 Demonstrate simple classification using a multi-layer perceptron</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [C,rate]=confmat(Y,T)</a>
0002 <span class="comment">%CONFMAT Compute a confusion matrix.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">%    Description</span>
0005 <span class="comment">%    [C, RATE] = CONFMAT(Y, T) computes the confusion matrix C and</span>
0006 <span class="comment">%    classification performance RATE for the predictions mat{y} compared</span>
0007 <span class="comment">%    with the targets T.  The data is assumed to be in a 1-of-N encoding,</span>
0008 <span class="comment">%    unless there is just one column, when it is assumed to be a 2 class</span>
0009 <span class="comment">%    problem with a 0-1 encoding.  Each row of Y and T corresponds to a</span>
0010 <span class="comment">%    single example.</span>
0011 <span class="comment">%</span>
0012 <span class="comment">%    In the confusion matrix, the rows represent the true classes and the</span>
0013 <span class="comment">%    columns the predicted classes.  The vector RATE has two entries: the</span>
0014 <span class="comment">%    percentage of correct classifications and the total number of correct</span>
0015 <span class="comment">%    classifications.</span>
0016 <span class="comment">%</span>
0017 <span class="comment">%    See also</span>
0018 <span class="comment">%    CONFFIG, DEMTRAIN</span>
0019 <span class="comment">%</span>
0020 
0021 <span class="comment">%    Copyright (c) Ian T Nabney (1996-2001)</span>
0022 
0023 [n c]=size(Y);
0024 [n2 c2]=size(T);
0025 
0026 <span class="keyword">if</span> n~=n2 | c~=c2
0027   error(<span class="string">'Outputs and targets are different sizes'</span>)
0028 <span class="keyword">end</span>
0029 
0030 <span class="keyword">if</span> c &gt; 1
0031   <span class="comment">% Find the winning class assuming 1-of-N encoding</span>
0032   [maximum Yclass] = max(Y', [], 1);
0033 
0034   TL=[1:c]*T';
0035 <span class="keyword">else</span>
0036   <span class="comment">% Assume two classes with 0-1 encoding</span>
0037   c = 2;
0038   class2 = find(T &gt; 0.5);
0039   TL = ones(n, 1);
0040   TL(class2) = 2;
0041   class2 = find(Y &gt; 0.5);
0042   Yclass = ones(n, 1);
0043   Yclass(class2) = 2;
0044 <span class="keyword">end</span>
0045 
0046 <span class="comment">% Compute</span>
0047 correct = (Yclass==TL);
0048 total=sum(sum(correct));
0049 rate=[total*100/n total];
0050 
0051 C=zeros(c,c);
0052 <span class="keyword">for</span> i=1:c
0053   <span class="keyword">for</span> j=1:c
0054     C(i,j) = sum((Yclass==j).*(TL==i));
0055   <span class="keyword">end</span>
0056 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Tue 26-Sep-2006 10:36:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>